function initUserState() {
  return {
    username: '小沐沐吖',
    password: '123456',
  };
}

/**
 * 数据
 */
const state = initUserState();

/**
 * 同步操作
 */
const mutations = {
  SET_USERNAME: (state, username) => {
    state.username = username;
  },
};

/**
 * 异步操作
 */
const actions = {
  getUserInfo({ commit }, user) {
    return new Promise(async (resolve, reject) => {
      try {
        const userInfo = await fetch('/api/getUserInfo', user);
        commit('SET_USERNAME', userInfo.data.username);
        resolve(userInfo);
      } catch (error) {
        reject(error);
      }
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
